const db = require('../database/mysql');
// 获取电影列表
exports.getdata = (req,res)=>{
    sqlString = 'select * from video'
    db.query(sqlString,(err,result)=>{
        if (err) {
            return res.cc(err,1);
        }else{
            res.send({
                status:200,
                msg:"查询数据库成功！！",
                data:result,
            })
        }
    });
}
// 获取用户信息表
exports.getUserInfo=(req,res)=>{
    const sqlstr = 'SELECT id,username,isdeleted FROM sy_users WHERE isdeleted = ? ';
    db.query(sqlstr,0,(err,result)=>{
        if (err) {
            return res.cc(err,1);
        } else if(result.length>0) {
            console.log("获取结果为：",result);
            res.send({
                status:200,
                msg:"获取信息成功",
                data:result,
            });
        }else{
            res.send({
                status:200,
                msg:"暂无用户！",
                data:result,
            });
        }
    });
}
// 更改密码
exports.updatePassword = (req,res)=>{
    const sqlstr = 'UPDATE sy_users SET password = ? WHERE username = ? ';
    const userInfo = req.body;
    console.log(userInfo)
    db.query(sqlstr,[userInfo.password,userInfo.username],(err,result)=>{
      if(result.affectedRows === 1) {
            res.send({
                status:200,
                msg:"修改密码成功！"
            })
        }else{
            return res.cc("无此账号,请输入正确的账号！",1);
        }
    });
}
